package com.ruoyi.controller.jpjs.person;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.SysParameterService;
import com.ruoyi.service.jpjs.param.ParamService;
import com.ruoyi.service.jpjs.person.PersonService;
import com.ruoyi.service.jpjs.project.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/person")
public class PersonController extends BaseController {

    private String prefix = "jpjs/person";

    @Autowired
    private ParamService paramService;
    @Autowired
    private PersonService personService;

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String person(ModelMap mmp) {
        mmp.put("personType", paramService.findParam("人员类型"));
        return prefix + "/Person";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findPerson(@RequestParam Map<String, Object> map) {
        List<Map<String, Object>> list = personService.findPersonAll(map);
        return getDataTable(list);
    }

    @GetMapping("/add")
    public String addPerson(ModelMap mmp) {
        mmp.put("personType", paramService.findParam("人员类型"));
        return prefix + "/add";
    }

    @PostMapping("/save")
    @ResponseBody
    public AjaxResult savePerson(@RequestParam Map<String, Object> map) {
        return toAjax(personService.savePerson(map));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult removePerson(String ids) {
        return toAjax(personService.deletePerson(ids));
    }

    @GetMapping("/edit/{id}")
    public String editPerson(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("personType", paramService.findParam("人员类型"));
        mmp.put("person", personService.findPerson(id));
        return prefix + "/edit";
    }
}
